﻿using System;
using System.Collections.Generic;
using System.Text;

namespace IAM.Interface.Common
{
    public static class EnDeCoding
    {
        /// <summary>
        /// 编码
        /// </summary>
        /// <param name="str">待编码的字符串</param>
        /// <returns></returns>
        public static string Encode(string str)
        {
            try
            {
                if (str == null)
                {
                    return "";
                }
                else
                {
                    return System.Web.HttpUtility.UrlEncode(str.ToString());
                }
            }
            catch
            {
                return "";
            }
        }

        /// <summary>
        /// 解码
        /// </summary>
        /// <param name="str">待解码的字符串</param>
        /// <returns></returns>
        public static string Decode(string str)
        {
            try
            {
                if (str == null)
                {
                    return "";
                }
                else
                {
                    return System.Web.HttpUtility.UrlDecode(str.ToString());
                }
            }
            catch
            {
                return "";
            }
        }
    }
}
